﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UDS.Components;

namespace UDS.SubModule.UnitiveDocument.DocumentFlowPages
{
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public partial class FlowTemplatePage : Page
    {
        private int _activeNodeId;
        private string _userName;

        protected bool ManageFlow
        {
            get;
            private set;
        }

        protected override void OnLoad(EventArgs e)
        {
            _userName = SiteContext.Current.UserName;

            // Get the id of the active node
            _activeNodeId = SiteContext.Current.ActiveNodeID;
            ManageFlow = AssignRights.IsAccessAllowed(_userName, _activeNodeId, PermissionType.ManageFlow);

            if (!Page.IsPostBack)
            {
                Bangding();
            }

            base.OnLoad(e);
        }

        #region 绑定DBGRID

        private void Bangding()
        {
            var mySQL = new Database();
            var parameters = new[]
            {
                Database.MakeInParam("@StaffName", SqlDbType.NVarChar, 300, _userName)
            };

            DataTable dt;
            using (var dr = mySQL.RunDataReader("dbo.sproc_Flow_GetMyFlow_V2", parameters))
            {
                dt = Tools.ConvertDataReaderToDataTable(dr);
            }

            dgFlowList.DataSource = dt.DefaultView;
            dgFlowList.DataBind();
        }

        #endregion

        #region 翻页事件

        public void DataGrid_PageChanged(object sender, DataGridPageChangedEventArgs e)
        {
            dgFlowList.CurrentPageIndex = e.NewPageIndex;
            Bangding();
        }

        #endregion
    }
}